package com.zyx.strategy.stg05;

import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;

/**
 * @author Yaxi.Zhang
 * @since 2022/10/10 01:17
 */
@Service(value = "fiveHandlerContext")
public class FiveHandlerContext {
    private final Map<String, AbstractFiveHandler> fiveHandlerMap = new ConcurrentHashMap<>();

    public void register(AbstractFiveHandler fiveHandler) {
        fiveHandlerMap.put(fiveHandler.getType(), fiveHandler);
    }

    public AbstractFiveHandler selectOne(String type) {
        AbstractFiveHandler fiveHandler = fiveHandlerMap.get(type);
        if (fiveHandler == null) {
            throw new RuntimeException("can not find handler");
        }
        return fiveHandler;
    }

}
